#include <stdio.h>
#include <string.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/select.h>
#include <fcntl.h>
#include <unistd.h>

#define MAX_LEN 64

int main(int argc, char **argv)
{
	int fd;
	int max_fd;
	fd_set readfd;
	fd_set writefd;

	//open
	fd = open("/dev/hello_dev", O_RDWR);
	if(fd < 0) {
		perror("open error \n");
		return 0;
	}
	printf("open success \n");

	while(1)
	{
		FD_ZERO(&readfd);
		FD_ZERO(&writefd);
		FD_SET(fd, &readfd);
		FD_SET(fd, &writefd);

		select(fd+1, &readfd, &writefd, NULL, NULL);
		if(FD_ISSET(fd, &readfd))
			printf("can read \n");
		if(FD_ISSET(fd, &writefd))
			printf("can write \n");
		sleep(1);
	}

	return 0;
}
